let vue = new Vue({
   el:'#app',
      // 修改Vue读取变量的语法，防止与jinja2混淆
    delimiters: ['[[', ']]'],
   data:function (){
       return {
           username:'',
           error_username:false, // 校验用户名是否有错
           password:'',
           error_password:'',// 校验密码是否有错
           remembered:false,//是否记住用户名和密码
       }
   },
    methods:{
       // 登录表单提交
       on_submit(){
           this.check_username();
            this.check_password();

            if (this.error_username == true || this.error_password == true) {
                // 不满足登录条件：禁用表单
				window.event.returnValue = false
            }
       },
       //校验用户名
        check_username(){
          let re = /^[a-zA-Z0-9_-]{5,20}$/;
			if (re.test(this.username)) {
                this.error_username = false;
            } else {
                this.error_username = true;
            }
        },
        // 校验密码
        check_password(){
          let re = /^[0-9A-Za-z]{8,20}$/;
			if (re.test(this.password)) {
                this.error_password = false;
            } else {
                this.error_password = true;
            }
        },
        // qq登录
        qq_login(){
           let next = get_query_string('next') || '/';
            let url = '/qq/login/?next=' + next;
            axios.get(url, {
                responseType: 'json'
            })
                .then(response => {
                    location.href = response.data.login_url;
                })
                .catch(error => {
                    console.log(error.response);
                })
        }
    }
})